<template>
	<om-addpage  :scrollTop="scrollTop" style="padding-top: 35px;" :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit">
		<om-autoform ref="autoform" :initConfigData="mainConfigData" :initValue="initValue"></om-autoform>
	</om-addpage>
</template>

<script>
	import {
		errorModal,
		ignoreHtml,
		getUrl,
		confirmModal,
		ptFloat,
		minusF
	} from '@/static/js/common.js';
	import {
		changeConfigAttr,
		buildFormData,
		formValidation,
		tranferToEditors,
		changeEditor,
		setSubmitSubValue,
		configSelectData,
		hasValue,
		formShowLoading,
		getFormFields,
		formModelLoad,
		getWorkCacheKey
	} from '@/static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildFormData({
				scrollTop:0
			})
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId'])
		},
		methods:{
			formSubmit(){
				let _that = this
				let arr = []
				for(let index in _that.subEditorObj["posCareercatInfo"].workList){
					if(!_that.subEditorObj["posCareercatInfo"].workList[index].adjustPosGradeId){
						arr.push(Number(index)+1)
					}
				}
				if(arr.length>0){
					errorModal(_that,"提示信息","保存失败，表格中的第"+arr+"行未编辑完成，请继续编辑！")
					return
				}
				_that.om.formSave("tposGradeAdjust/addTposGradeAdjust",_that.formdata,_that)
			},
			getDataList(){
				let _that = this
				_that.om.request(
					"tposGradeAdjust/getDataList"
				).then(res=>{
					_that.subEditorObj["posCareercatInfo"].workList = res.value
					_that.$refs.autoform.changeConfigAttr("posCareercatInfo","length",res.value.length || 0)
				})
			},
			initLoad(options){
				let _that = this
				let ajaxArr = [
					urlUtil.zposUrl(options.code)
				]
				ajaxArr.push({
					url:'tposGradeAdjust/getDataList'
				})
				let fileId = options.fileID
				if(fileId){
					ajaxArr.push({
						url:"tposGradeAdjust/getInfo",
						param:{
							id:fileId
						}
					})
				}
				formModelLoad(ajaxArr,function(res,mainData){
					changeEditor("topinfo","zposId","data",configSelectData(res[0],"id","posname"),mainData)
					changeConfigAttr("posCareercatInfo","showLength",true,mainData)
					if(_that.subEditorObj["posCareercatInfo"]){
						changeEditor("posCareercatInfo","objStr",{
							showAdd:false,
							showArrow:false,
							showLength:true,
							length:0,
							showDel:false,
							titleTemplate:"机构名称:<%= instName || '未填写'%> |岗位名称:<%=posName || '未填写'%>",
							subtitle1Template:"计酬方式:<%=salary || '未填写'%>|测评职级:<%=testGrade || '未填写'%>|原岗位职级:<%=origPosGrade || '未填写'%>",
							subtitle2Template:"拟调整岗位职级:<%=adjustPosGradeName || '未填写'%>|职级月薪范围:<%=gradeSalaryRange || '未填写'%>"
						},null,mainData)
					}
					if(fileId){
						let fieldArr = getFormFields(mainData)
						fieldArr.push("id")
					}
					_that.$nextTick(function(){
						_that.getDataList()
					})	
				},options)
			}
		},
		onUnload(){
					//#ifdef APP-PLUS
					let _that = this;
					if (_that.$refs.autoform) {
						for (var fieldId in _that.subEditorObj) {
							uni.removeStorage({
								key: getWorkCacheKey(fieldId)
							});
						}
					}
					//#endif
				},
		onLoad(options) {
			let _that = this
			_that.initLoad(options)
		},
		onPageScroll(e) {
			if(e.scrollTop > 150){
				this.scrollTop = e.scrollTop
			}else{
				this.scrollTop = 0
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				for(let fieldId in _that.subEditorObj){
					let editor = _that.subEditorObj[fieldId]
					uni.getStorage({
						key:getWorkCacheKey(fieldId),
						success:(res)=>{
							editor.workList = res.data
							uni.removeStorage({
								key:getWorkCacheKey(fieldId)
							})
						}
					})
				}
			}
		}
	}
</script>

<style></style>                                                                                                                                                                                                                                                                                                                                      
